<template>
  <div class="params">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>分类参数</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-alert title="注意：只允许为第三级分类设置相关参数！" type="info" :closable="false" show-icon></el-alert>
      <!-- 级联选择器 -->
      <p>
        选择商品分类：
        <el-cascader
          v-model="cascaderArr"
          :options="cascaderOptions"
          :props="props"
          @change="handleChange"
        ></el-cascader>
      </p>
      <!-- 数据展示部分 -->
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="动态参数" name="many">
          <el-row>
            <el-button
              type="primary"
              size="mini"
              :disabled="disabled"
              @click="dialogAdd = true"
            >添加参数</el-button>
          </el-row>
          <el-table :data="manyList" border>
            <el-table-column type="expand">
              <template slot-scope="scope">
                <el-tag
                  :style="tag == ''? 'display:none':'display:inner-block'"
                  :key="tag"
                  v-for="tag in scope.row.attr_vals"
                  closable
                  :disable-transitions="false"
                  @close="handleClose(scope.row,tag)"
                >{{tag}}</el-tag>
                <el-input
                  style="width:100px"
                  class="input-new-tag"
                  v-if="inputVisible"
                  v-model="inputValue"
                  ref="saveTagInput"
                  size="small"
                  @keyup.enter.native="handleInputConfirm(scope.row)"
                  @blur="handleInputConfirm(scope.row)"
                ></el-input>
                <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column label="参数名称" prop="attr_name"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="searchParams(scope.row)">修改</el-button>
                <el-button type="danger" size="mini" @click="deleteParams(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="静态属性" name="only">
          <el-row>
            <el-button
              type="primary"
              size="mini"
              :disabled="disabled"
              @click="dialogAdd = true"
            >添加属性</el-button>
          </el-row>
          <el-table :data="onlyList" border>
            <el-table-column type="expand">
              <template slot-scope="scope">
                <el-tag
                  :style="{display:tag == ''? 'none':'inner-block'}"
                  :key="tag"
                  v-for="tag in scope.row.attr_vals"
                  closable
                  :disable-transitions="false"
                  @close="handleClose(scope.row,tag)"
                >{{tag}}</el-tag>
                <el-input
                  style="width:100px"
                  class="input-new-tag"
                  v-if="inputVisible"
                  v-model="inputValue"
                  ref="saveTagInput"
                  size="small"
                  @keyup.enter.native="handleInputConfirm(scope.row)"
                  @blur="handleInputConfirm(scope.row)"
                ></el-input>
                <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column label="参数名称" prop="attr_name"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="searchParams(scope.row)">修改</el-button>
                <el-button type="danger" size="mini" @click="deleteParams(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- 添加弹框 -->
    <el-dialog :title="activeName=='many'? '添加动态参数':'添加静态属性'" :visible.sync="dialogAdd">
      <el-form :model="addParamsForm">
        <el-form-item :label="activeName=='many'? '动态参数':'静态属性'">
          <el-input v-model="addParamsForm.attr_name"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAdd = false">取 消</el-button>
        <el-button type="primary" @click="addParams">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 修改弹框 -->
    <el-dialog :title="activeName=='many'? '修改动态参数':'修改静态属性'" :visible.sync="dialogUpd">
      <el-form :model="addParamsForm">
        <el-form-item :label="activeName=='many'? '动态参数':'静态属性'">
          <el-input v-model="addParamsForm.attr_name"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAdd = false">取 消</el-button>
        <el-button type="primary" @click="updateParams">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import params from "./params-mixins";
export default {
  mixins: [params]
};
</script>
<style lang="less" scoped>
.el-card {
  margin-top: 15px;
}
p {
  margin-top: 15px;
}
.el-row {
  margin-bottom: 15px;
}
.el-tag {
  margin-right: 5px;
}
</style>
